﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;

namespace Quản_Lý_Thư_Viện
{
    
        class DataProvider
        {
            // Ho Tram Si Ha
            protected SqlConnection connection = new SqlConnection();
            protected SqlCommand command;


            public void connect()
            {
                connection.ConnectionString = "Data Source=localhost;Initial Catalog=quanlytv;Integrated Security=True";
                connection.Open();
            }

            public void Close()
            {
                connection.Dispose();
            }

            public void executeNonQuery(string sqlString)
            {
                command = new SqlCommand(sqlString, connection);
                command.ExecuteNonQuery();
            }
            public IDataReader executeQuery(string sqlString)
            {
                command = new SqlCommand(sqlString, connection);
                return command.ExecuteReader();
            }
            public DataTable GetData(string sql)
            {
                SqlDataAdapter adapter = new SqlDataAdapter(sql, connection);
                DataTable dt = new DataTable();
                adapter.Fill(dt);
                adapter.Dispose();
                dt.Dispose();
                return dt;
            }

            public void ExecuteWithObject(string sqlString, string objString,object obj)
            {
                SqlCommand cmd = new SqlCommand(sqlString, connection);
                cmd.Parameters.Add(new SqlParameter(objString,(object)obj));
                cmd.ExecuteNonQuery();
            }
        }
    }
